var e = require("../../3D336854875DE5CF5B550053BF4D6824.js"), o = {
    female: "女",
    male: "男"
}, t = null, a = null;

Page({
    data: {
        type: "",
        filePath: "",
        gender: "",
        age: "",
        beauty: "",
        img_url: ""
    },
    onLoad: function(e) {
        console.log("facedetail options"), console.log(e);
        var o = e.type;
        this.setData({
            type: o
        }), null != e.filePath && (a = e.filePath, this.recognize(a)), this.loadInterstitialAd();
    },
    loadInterstitialAd: function() {
        wx.createInterstitialAd && ((t = wx.createInterstitialAd({
            adUnitId: "adunit-4f7485ed7645a8f2"
        })).onLoad(function() {
            console.log("ad onLoad event emit");
        }), t.onError(function(e) {
            console.log("ad onError event emit", e);
        }), t.onClose(function(e) {
            console.log("ad onClose event emit", e);
        }));
    },
    showInterstitialAd: function() {
        t && t.show().catch(function(e) {
            console.log("插屏广告显示失败"), console.error(e);
        });
    },
    recognize: function(t) {
        var a = this;
        e.recognizeFace(t).then(function(e) {
            if (e) {
                if (console.log("detail face:"), console.log(e), 200 != e.res.code) return a.setData({
                    filePath: "",
                    age: "",
                    beauty: "",
                    gender: "",
                    imgurl: ""
                }), void wx.showModal({
                    title: "提示",
                    content: e.res.message,
                    showCancel: !1,
                    complete: function(e) {
                        e.confirm && wx.navigateBack();
                    }
                });
                var n = e.res.result;
                console.log("faceData"), console.log(n);
                var i = n.beauty, l = "";
                null != n.img_url && "" != n.img_url && (l = n.img_url), a.setData({
                    filePath: t,
                    age: n.age,
                    beauty: i,
                    gender: o[n.gender],
                    img_url: l
                });
                var s = util.todayDate() + "_close_ad", c = wx.getStorageSync(s) || !1;
                console.log("是否关闭今日广告:" + c), 0 == c && a.showInterstitialAd();
            } else console.log("未获取到识别结果"), wx.showToast({
                title: "无法识别"
            });
        });
    },
    previewImage: function(e) {
        wx.previewImage({
            urls: this.data.filePath.split(",")
        });
    },
    chooseImage: function() {
        var e = this;
        wx.chooseImage({
            count: 1,
            sizeType: [ "compressed" ],
            sourceType: [ "camera", "album" ],
            success: function(o) {
                console.log("choose image success:"), console.log(o);
                var t = o.tempFilePaths[0];
                e.setData({
                    filePath: t
                }), e.recognize(t);
            },
            fail: function(e) {
                console.log("取消了");
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onShareAppMessage: function(e) {
        var o = this.data.gender, t = this.data.age, a = this.data.beauty, n = this.data.img_url, i = "/pages/face/shared?type=face&gender=" + o + "&age=" + t + "&beauty=" + a + "&img_url=" + n;
        return console.log("face detail path:"), console.log(i), {
            title: "我的颜值" + a + "分，来跟我PK一下吧",
            imageUrl: n,
            path: i,
            success: function(e) {
                console.log("颜值打分分享成功");
            },
            fail: function(e) {}
        };
    }
});